package com.microcore.dao.mapper;

import org.apache.ibatis.jdbc.SQL;

import com.microcore.entity.InvokeTrigger;

public class InvokeTriggerSqlProvider {

    public String insertSelective(InvokeTrigger record) {
        SQL sql = new SQL();
        sql.INSERT_INTO("tb_ssgp_invoke_trigger");

        if (record.getInvokeTriggerId() != null) {
            sql.VALUES("trigger_id", "#{invokeTriggerId,jdbcType=VARCHAR}");
        }

        if (record.getFkId() != null) {
            sql.VALUES("foreign_key_id", "#{fkId,jdbcType=VARCHAR}");
        }

        if (record.getStartDatetime() != null) {
            sql.VALUES("start_datetime", "#{startDatetime,jdbcType=TIMESTAMP}");
        }

        if (record.getEndDatetime() != null) {
            sql.VALUES("end_datetime", "#{endDatetime,jdbcType=TIMESTAMP}");
        }

        if (record.getCount() != null) {
            sql.VALUES("count", "#{count,jdbcType=INTEGER}");
        }

        if (record.getInterval() != null) {
            sql.VALUES("trigger_interval", "#{interval,jdbcType=INTEGER}");
        }

        if (record.getCronExpression() != null) {
            sql.VALUES("cron_expression", "#{cronExpression,jdbcType=VARCHAR}");
        }

        if (record.getTriggerName() != null) {
            sql.VALUES("trigger_name", "#{triggerName,jdbcType=VARCHAR}");
        }
        
        if (record.getParams() != null) {
            sql.VALUES("params", "#{params,jdbcType=VARCHAR}");
        }

       /* if (record.getStartTime() != null) {
            sql.VALUES("start_time", "#{startTime,jdbcType=VARCHAR}");
        }

        if (record.getEndTime() != null) {
            sql.VALUES("end_time", "#{endTime,jdbcType=VARCHAR}");
        }*/

        return sql.toString();
    }

    public String updateByPrimaryKeySelective(InvokeTrigger record) {
        SQL sql = new SQL();
        sql.UPDATE("tb_ssgp_invoke_trigger");

        if (record.getFkId() != null) {
            sql.SET("foreign_key_id = #{fkId,jdbcType=VARCHAR}");
        }

        if (record.getStartDatetime() != null) {
            sql.SET("start_datetime = #{startDatetime,jdbcType=TIMESTAMP}");
        }

        if (record.getEndDatetime() != null) {
            sql.SET("end_datetime = #{endDatetime,jdbcType=TIMESTAMP}");
        }

        if (record.getCount() != null) {
            sql.SET("count = #{count,jdbcType=INTEGER}");
        }

        if (record.getInterval() != null) {
            sql.SET("trigger_interval = #{interval,jdbcType=INTEGER}");
        }

        if (record.getCronExpression() != null) {
            sql.SET("cron_expression = #{cronExpression,jdbcType=VARCHAR}");
        }

        if (record.getTriggerName() != null) {
            sql.SET("trigger_name = #{triggerName,jdbcType=VARCHAR}");
        }
        
        if (record.getParams() != null) {
            sql.SET("params = #{params,jdbcType=VARCHAR}");
        }

       /* if (record.getStartTime() != null) {
            sql.SET("start_time = #{startTime,jdbcType=VARCHAR}");
        }

        if (record.getEndTime() != null) {
            sql.SET("end_time = #{endTime,jdbcType=VARCHAR}");
        }*/

        sql.WHERE("trigger_id = #{invokeTriggerId,jdbcType=VARCHAR}");

        return sql.toString();
    }
}
